<?php
/* SVN FILE: $Id: menu.php 51 2007-09-29 19:10:02Z joe.vasquez $ */
/**
 * menu component
 * @filesource
 * @author			Joe Vasquez <joe.vasquez@gmail.com>
 * @copyright		Copyright (c) 2007, Joe Vasquez
 * @package			redlettr
 * @subpackage		components
 * @since			0.1A
 * @version			0.1A  $Rev: 51 $
 * @lastmodified	$Date: 2007-09-29 19:10:02 +0000 (Sat, 29 Sep 2007) $
 * @license			http://www.gnu.org/licenses/gpl.html GNU General Public License
 */
 
class MenuComponent extends Object {
	var $__menu = null;
	var $controller = true;
	
	function startup(&$controller)
	{
		$this->controller = $controller;
		$this->__menu = array();
	}
	
	function hasMenu()
	{
		return (is_array($this->__menu) && count($this->__menu) > 0);
	}
	
	function createMenu($name='default')
	{
		if(is_array($name))
		{
			$this->__menu[] = $name;
		}
		if(!array_key_exists($name,$this->__menu))
		{
			$this->__menu[$name] = array();
		}
	}
	
	function addItem($item,$menu='default')
	{
		if(!array_key_exists($menu,$this->__menu))
		{
			$this->createMenu($menu);
		}
		if(is_array($item))
		{
			if(!array_key_exists('title', $item)) {
				$this->__menu[$menu][] = array(
					'title'	=> array_pop(array_keys($item)),
					'url'	=> array_pop(array_values($item))
				);
			}
		} else {
			$this->__menu[$menu][] = $item;
		}
	}
	
	function addItems($items,$menu='default')
	{
		foreach($items as $item)
		{
			$this->addItem($item,$menu);
		}
	}	
	
	function deleteMenu($menu)
	{
		unset($this->__menu[$menu]);
	}
	
	function getMenu()
	{
		return $this->__menu;
	}
	
	function setMenu()
	{
		$this->controller->set('menus',$this->__menu);
	}
}
?>